package com.software.graduationproject.modules.comment.web;

import com.baomidou.mybatisplus.core.metadata.Page;

import com.software.graduationproject.commons.select.Select;
import com.software.graduationproject.commons.util.Result;
import com.software.graduationproject.commons.util.Results;
import com.software.graduationproject.modules.comment.entity.Comment;
import com.software.graduationproject.modules.comment.object.CommentVo;
import com.software.graduationproject.modules.comment.service.CommentService;
import com.software.graduationproject.modules.comment.object.CommentCreateQo;
import com.software.graduationproject.modules.comment.object.CommentUpdateQo;

import com.v2coding.validate.CreateGroup;
import com.v2coding.validate.UpdateGroup;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * CommentController : 评论表
 * ---------------------------------------------------------------------------------------------------------------------
 */
@Validated
@RestController
@RequestMapping("/Comment/Comment")
@Api(value = "API - 评论表", tags = {"评论表接口"})
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/create")
    @ApiOperation("新增评论表")
    public Result createQo(@RequestBody @Validated(CreateGroup.class) CommentCreateQo qo) {
        commentService.createQo(qo);
        return Results.success();
    }

    @PostMapping("/update")
    @ApiOperation("修改评论表")
    public Result updateQo(@RequestBody @Validated(UpdateGroup.class) CommentUpdateQo qo) {
        commentService.updateQo(qo);
        return Results.success();
    }

    @PostMapping("/delete")
    @ApiOperation("删除评论表")
    public Result delete(@RequestBody Long id) {
        commentService.delete(id);
        return Results.success();
    }
//
//    @PostMapping("/deleteList")
//    @ApiOperation("批量删除评论表")
//    public Result deleteList(@RequestBody Long []ids) {
//        commentService.deleteList(ids);
//        return Results.success();
//    }

    @GetMapping("/select")
    @ApiOperation("查询评论表详情")
    public Result<CommentVo> selectVo(Long id) {
        CommentVo commentVo = commentService.selectVo(id);
        return Results.success(commentVo);
    }

    @GetMapping("/selectList")
    @ApiOperation("查询评论表列表")
    @ApiImplicitParams({ //
            @ApiImplicitParam(name = "select", value = "查询条件", required = false, dataTypeClass = String.class, paramType = "query"),//
    })
    public Result<List<CommentVo>> selectListVo(@ApiIgnore Select select) {
        List<CommentVo> commentVoList = commentService.selectListVo(select);
        return Results.success(commentVoList);
    }

    @GetMapping("/selectPage")
    @ApiOperation("查询评论表分页")
    @ApiImplicitParams({ //
            @ApiImplicitParam(name = "select", value = "查询条件", required = false, dataTypeClass = String.class, paramType = "query"),//
    })
    public Result<Page<CommentVo>> selectPageVo(@ApiIgnore Select select) {
        Page<CommentVo> commentVoPage = commentService.selectPageVo(select);
        return Results.success(commentVoPage);
    }


}
